<?php
// +----------------------------------------------------------------------
// | Project [ Weaving Tools ] 开源
// +----------------------------------------------------------------------
// | Copyright (c) 2020 https://gitee.com/sexz All rights reserved.
// +----------------------------------------------------------------------
// | Gitee https://gitee.com/sexz/Weaving-Tools 
// +----------------------------------------------------------------------
// | Author: xinyan <2687409344@qq.com>
// +----------------------------------------------------------------------

# 函数库

function send_get($url, $post = 0, $referer = 0, $cookie = 0, $header = 0, $ua = 0, $nobaody = 0)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    $httpheader[] = "Accept:*/*";
    $httpheader[] = "Accept-Encoding:gzip,deflate,sdch";
    $httpheader[] = "Accept-Language:zh-CN,zh;q=0.8";
    $httpheader[] = "Connection:close";
    curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    if ($post) {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    }
    if ($header) {
        curl_setopt($ch, CURLOPT_HEADER, TRUE);
    }
    if ($cookie) {
        curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    }
    if ($referer) {
        if ($referer == 1) {
            curl_setopt($ch, CURLOPT_REFERER, 'http://m.qzone.com/infocenter?g_f=');//Qzone_Referer
        } else {
            curl_setopt($ch, CURLOPT_REFERER, $referer);
        }
    }
    if ($ua) {
        curl_setopt($ch, CURLOPT_USERAGENT, $ua);
    } else {
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Linux; Android 4.4.2; NoxW Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36');
    }
    if ($nobaody) {
        curl_setopt($ch, CURLOPT_NOBODY, 1);
    }
    curl_setopt($ch, CURLOPT_ENCODING, "gzip");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $ret = curl_exec($ch);
    curl_close($ch);
    return $ret;
}

function is_fz_add_day($int)
{
    switch ($int) {
        case 1:
            $day = 7;
            break;
        case 2:
            $day = 30;
            break;
        case 3:
            $day = 60;
            break;
        case 4:
            $day = 180;
            break;
        case 5:
            $day = 365;
            break;
    }
    return $day;
}

function back_list($content)
{
    $keyword = explode(',', config('sys_backlist'));
    $content2 = preg_replace('/\W/', '', $content);
    $m = 0;
    for ($i = 0; $i < count($keyword); $i++) {    //根据数组元素数量执行for循环
        //应用substr_count检测内容中是否包含敏感词
        if (substr_count($content, $keyword [$i]) > 0) {
            $m++;
        }
    }
    return $m; //返回变量值，根据变量值判断是否存在敏感词
}

function time_tran($the_time) {
    $now_time = date("Y-m-d H:i:s", time());
    $now_time = strtotime($now_time);
    $show_time = strtotime($the_time);
    $dur = $now_time - $show_time;
    if ($dur < 0) {
        return $the_time;
    } else {
        if ($dur < 60) {
            return $dur . '秒前';
        } else {
            if ($dur < 3600) {
                return floor($dur / 60) . '分钟前';
            } else {
                if ($dur < 86400) {
                    return floor($dur / 3600) . '小时前';
                } else {
                    if ($dur < 2592000) {//30天内
                        return floor($dur / 86400) . '天前';
                    } else {
						if ($dur < 31104000) {//12月内
							return floor($dur / 2592000) . '月前';
						}else{
							if ($dur < 3110400000) {//100年内
								return floor($dur / 31104000) . '年前';
							} else{
								return $the_time;
							}
						}
					}
				}
			}
		}
	}
}

function jump()
{
	$siteurl = get_domain();
	echo '<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>请使用浏览器打开</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport"/>
    <meta content="yes" name="apple-mobile-web-app-capable"/>
    <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
    <meta name="format-detection" content="telephone=no"/>
    <meta content="false" name="twcClient" id="twcClient"/>
    <meta name="aplus-touch" content="1"/>
    <style>
body,html{width:100%;height:100%}
*{margin:0;padding:0}
body{background-color:#fff}
.top-bar-guidance{font-size:15px;color:#fff;height:70%;line-height:1.8;padding-left:20px;padding-top:20px;background:url(//gw.alicdn.com/tfs/TB1eSZaNFXXXXb.XXXXXXXXXXXX-750-234.png) center top/contain no-repeat}
.top-bar-guidance .icon-safari{width:25px;height:25px;vertical-align:middle;margin:0 .2em}
.app-download-tip{margin:0 auto;width:290px;text-align:center;font-size:15px;color:#2466f4;background:url() left center/auto 15px repeat-x}
.app-download-tip .guidance-desc{background-color:#fff;padding:0 5px}
.app-download-btn{display:block;width:214px;height:40px;line-height:40px;margin:18px auto 0 auto;text-align:center;font-size:18px;color:#2466f4;border-radius:20px;border:.5px #2466f4 solid;text-decoration:none}
    </style>
</head>
<body>
<div class="top-bar-guidance">
    <p>点击右上角<img src="//gw.alicdn.com/tfs/TB1xwiUNpXXXXaIXXXXXXXXXXXX-55-55.png" class="icon-safari" /> <span id="openm">Safari打开</span></p>
    <p>可以继续浏览本站哦~</p>
</div>
<div class="app-download-tip">
    <span class="guidance-desc">您也可以复制本站网址，到其它浏览器打开</span>
</div>
<a data-clipboard-text="'.$siteurl.'" class="app-download-btn" id="J_BtnDowanloadApp">点此继续访问</a>
<a style="display: none;" href="" id="vurl" rel="noreferrer"></a>

<script src="//lib.baomitu.com/jquery/1.12.4/jquery.min.js"></script>
<script src="//open.mobile.qq.com/sdk/qqapi.js?_bid=152"></script>
<script>
function openu(u){
document.getElementById("vurl").href= u;
document.getElementById("vurl").click();
}
var url = window.location.href;
	document.querySelector(\'body\').addEventListener(\'touchmove\', function (event) {
		event.preventDefault();
	});
	if(navigator.userAgent.indexOf("Android") > -1){
		document.getElementById("openm").innerHTML=\'浏览器打开\';
	}
	if(navigator.userAgent.indexOf("QQ/") > -1){
		openu("mttbrowser://url="+url);
		$("html").on("click",function(){
			openu("mttbrowser://url="+url);
			openu("ucweb://"+url);
			openu("qihoobrowser://browse?url="+url);
			openu("googlechrome://browse?url="+url);
			openu("mibrowser:"+url);
			openu("taobao://"+url);
		});
		mqq.ui.openUrl({ target: 2,url: window.location.href});
	}else if(navigator.userAgent.indexOf("MicroMessenger") > -1){
		if(navigator.userAgent.indexOf("Android") > -1){
			var iframe = document.createElement("iframe");
			iframe.style.display = "none";
			iframe.src = \'?open=1\';
			document.body.appendChild(iframe);
		}
	}
</script>
</body>
</html>';
}

function is_ios()
{
    //全部变成小写字母
    $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
    if (strpos($agent, 'iphone') || strpos($agent, 'ipad')) {
        return true;
    }
    if (strpos($agent, 'android')) {
        return false;
    }
}

function daddslashes($string, $force = 0, $strip = FALSE)
{
    !defined('MAGIC_QUOTES_GPC') && define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
    if (!MAGIC_QUOTES_GPC || $force) {
        if (is_array($string)) {
            foreach ($string as $key => $val) {
                $string[$key] = daddslashes($val, $force, $strip);
            }
        } else {
            $string = addslashes($strip ? stripslashes($string) : $string);
        }
    }
    return $string;
}

function filter_default($value)
{
 return htmlspecialchars($value, ENT_NOQUOTES);
}

function pc_msg($title, $con)
{
    return '<script>
		layer.confirm(
			\'<div><h4 class="mt0 mb5">'.$title.'</h4></div><div>'.$con.'</div>\',
			{
				btn:\'我 知 道 了\',
				btnAlign:\'c\',
				yes:function(i){
					x.close(i);
					
				},
				btn2:function(i){
					x.close(i);
					
				}
			}
		);
		</script>';
}

function moblie_msg($title, $con)
{
    return '<script>
		layer.open({
			content: \'<h4 class="mt0 mb4">'.$title.'</h4><p>'.$con.'</p>\',
			btn: \'我 知 道 了\',
			shadeClose: false,
			yes: function(i){
				x.mclose(i);
				
				
			},
			no: function(i){
				x.mclose(i);
				
				
			}
		});
		</script>';
}

function timediff($begin_time, $end_time)
{
    if ($begin_time < $end_time) {
        $starttime = $begin_time;
        $endtime = $end_time;
    } else {
        $starttime = $end_time;
        $endtime = $begin_time;
    }
    $timediff = $endtime - $starttime;
    $days = intval($timediff / 86400);
    return $days;
}

function check_Hash($value, $hash)
{
    return password_verify($value, $hash);
}

function make_Hash($value)
{
    return password_hash($value, PASSWORD_DEFAULT);
}

function check_mail($mail)
{
    $checkmail = "/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/";//定义正则表达式
    if (preg_match($checkmail, $mail)) {
        return true;
    } else {
        return false;
    }
}

function check_number($s)
{
    if (preg_match("/^1[345678]{1}\d{9}$/", $s)) {
        return true;
    } else {
        return false;
    }
}

function check_url($url){
    if(!preg_match('/http:\/\/[\w.]+[\w\/]*[\w.]*\??[\w=&\+\%]*/is',$url)){
        return false;
    }
    return true;
}

function get_login_user($user)
{
    if (check_mail($user)) {
        $where['mail'] = $user;
    } elseif (check_number($user)) {
        $where['phone'] = $user;
    } else {
        $where['username'] = $user;
    }
    return $where;
}

function real_ip()
{
    $ip = $_SERVER['REMOTE_ADDR'];
    if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) {
        foreach ($matches[0] AS $xip) {
            if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip)) {
                $ip = $xip;
                break;
            }
        }
    } elseif (isset($_SERVER['HTTP_CLIENT_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CLIENT_IP'])) {
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    } elseif (isset($_SERVER['HTTP_CF_CONNECTING_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CF_CONNECTING_IP'])) {
        $ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
    } elseif (isset($_SERVER['HTTP_X_REAL_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_X_REAL_IP'])) {
        $ip = $_SERVER['HTTP_X_REAL_IP'];
    }
    return $ip;
}

function ip_city_str($str)
{
    return str_replace(array('省', '市'), '', $str);
}

function get_ip_city($ip)
{
    $url = 'https://cloud.qqlogin.com/Request/ipCity.api?ip=';
    $city = send_get($url . $ip);
    $city = json_decode($city, true);
    return $city['result'];
}

function is_gg_type($type = 0)
{
    switch ($type) {
        case 0:
            $result = '普通公告';
            break;
        case 1:
            $result = '广告推广';
            break;
        case 2:
            $result = '推荐链接';
            break;
    }
    return $result;
}

function is_vip_day($int)
{
    switch ($int) {
        case 1:
            $day = 30;
            break;
        case 2:
            $day = 90;
            break;
        case 3:
            $day = 180;
            break;
        case 4:
            $day = 365;
            break;
    }
    return $day;
}

function is_peie_num($int)
{
    switch ($int) {
        case 1:
            $num = 1;
            break;
        case 2:
            $num = 3;
            break;
        case 3:
            $num = 5;
            break;
        case 4:
            $num = 10;
            break;
    }
    return $num;
}

function get_domain()
{
    $siteurl = ($_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . '/';
    return $siteurl;
}

function getRandStr($len = 16, $type = 0)
{
    $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    $strlen = strlen($str);
    $randstr = '';
    for ($i = 0; $i < $len; $i++) {
        $randstr .= $str[mt_rand(0, $strlen - 1)];
    }
    if ($type == 1) {
        $randstr = strtoupper($randstr);
    } elseif ($type == 2) {
        $randstr = strtolower($randstr);
    }
    return $randstr;
}

function getRand($proArr)
{ //计算中奖概率
    $rs = ''; //z中奖结果
    $proSum = array_sum($proArr); //概率数组的总概率精度
    //概率数组循环
    foreach ($proArr as $key => $proCur) {
        $randNum = mt_rand(1, $proSum);
        if ($randNum <= $proCur) {
            $rs = $key;
            break;
        } else {
            $proSum -= $proCur;
        }
    }
    unset($proArr);
    return $rs;
}

function Pay($orderid, $name, $price, $type, $shop, $shopid)
{
    $epay_config = [
        'partner' => config('sys_epay_id'),
        'key' => config('sys_epay_key'),
        'sign_type' => strtoupper('MD5'),
        'input_charset' => strtolower('utf-8'),
        'transport' => 'http',
        'apiurl' => config('sys_epay_url')
    ];
    $parameter = array(
        "pid" => trim($epay_config['partner']),
        "type" => $type,
        "notify_url" => 'http://' . $_SERVER['HTTP_HOST'] . url('Epay/' . $shop . '_Notify'), //服务器异步通知页面路径
        "return_url" => 'http://' . $_SERVER['HTTP_HOST'] . url('Epay/' . $shop . '_Return'), //页面跳转同步通知页面路径
        "out_trade_no" => $orderid,
        "name" => $name,
        "money" => $price,
        "shop" => $shop,
        "shopid" => $shopid,
        "sitename" => config('web_webname')
    );
    //建立请求
    $alipaySubmit = new AlipaySubmit($epay_config);
    $html_text = $alipaySubmit->buildRequestForm($parameter, "get");
    echo $html_text;
}

function create_link($params, $codepay_key, $host = "")
{
	ksort($params); //重新排序$data数组
	reset($params); //内部指针指向数组中的第一个元素
	$sign = '';
	$urls = '';
	foreach ($params AS $key => $val) {
		if ($val == '') continue;
		if ($key != 'sign') {
			if ($sign != '') {
				$sign .= "&";
				$urls .= "&";
			}
			$sign .= "$key=$val"; //拼接为url参数形式
			$urls .= "$key=" . urlencode($val); //拼接为url参数形式
		}
	}

	$key = md5($sign . $codepay_key);//替换为自己的密钥
	$query = $urls . '&sign=' . $key; //创建订单所需的参数
	$apiHost = $host ? $host : "http://api2.fateqq.com:52888/creat_order/?";
	$url = $apiHost . $query; //支付页面
	return array("url" => $url, "query" => $query, "sign" => $sign, "param" => $urls);
}

function cookieZt($int)
{
    if ($int != 0) {
        return '失效';
    } else {
        return '正常';
    }
}

function is_zan($data)
{
    if ($data['start'] > 0) {
        return '秒赞运行中';
    } else {
        return '秒赞已关闭';
    }
}

function get_prefix($len = 4)
{
    $str = 'abcdefghijklmnopqrstuvwxyz0123456789';
    $strlen = strlen($str);
    $randstr = '';
    for ($i = 0; $i < $len; $i++) {
        $randstr .= $str[mt_rand(0, $strlen - 1)];
    }
    return $randstr;
}

function is_daili($power)
{
    switch ($power) {
        case 1:
            $daili_name = '银牌代理';
            break;
        case 2:
            $daili_name = '金牌代理';
            break;
        case 3:
            $daili_name = '钻石代理';
            break;
        default;
            $daili_name = '普通用户';
    }

    return $daili_name;
}

function is_vip($vip_time)
{
    if ($vip_time != '') {
        return 'VIP用户';
    } else {
        return '免费用户';
    }
}

function is_input_qq($uin)
{
    if (!preg_match('/^[0-9]+$/', $uin)) {
        return true;
    } else {
        return false;
    }
}

function get_qqnick($qq)
{
    $html = file_get_contents('http://r.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?uins='.$qq);
    $nic = explode(',',$html);
    $name = trim(mb_convert_encoding($nic[6], "UTF-8", "GBK"),'"');
    return $name;
}

function gnlist()
{
	$data = [
		[
			'name' => '说说秒赞',
			'id' => 'zan',
			'vip' => 0,
			'gnid'=> 1
		],[
			'name' => '说说秒评',
			'id' => 'reply',
			'vip' => 0,
			'gnid'=> 1
		],[
			'name' => '群聊签到',
			'id' => 'qunqd',
			'vip' => 0,
			'gnid'=> 2
		],[
			'name' => '互赞名片赞',
			'id' => 'hzmp',
			'vip' => 1,
			'gnid'=> 2
		],[
			'name' => '手Q加速',
			'id' => 'mqq',
			'vip' => 1,
			'gnid'=> 2
		],[
			'name' => '手游加速',
			'id' => 'sy',
			'vip' => 1,
			'gnid'=> 2
		],[
			'name' => '自动说说',
			'id' => 'shuo',
			'vip' => 1,
			'gnid'=> 1
		],[
			'name' => '转发说说',
			'id' => 'zf',
			'vip' => 1,
			'gnid'=> 1
		],[
			'name' => '情侣空间',
			'id' => 'ql',
			'vip' => 1,
			'gnid'=> 1
		],
		[
			'name' => '删除说说',
			'id' => 'del',
			'vip' => 1,
			'gnid'=> 1
		],[
			'name' => '删除留言',
			'id' => 'delly',
			'vip' => 1,
			'gnid'=> 1
		],[
			'name' => '花藤代养',
			'id' => 'ht',
			'vip' => 1,
			'gnid'=> 1
		],[
			'name' => '会员签到',
			'id' => 'hyqd',
			'vip' => 1,
			'gnid'=> 2
		],[
			'name' => '黄钻签到',
			'id' => 'hzqd',
			'vip' => 1,
			'gnid'=> 2
		],[
			'name' => '好莱坞签到',
			'id' => 'hlwqd',
			'vip' => 1,
			'gnid'=> 2
		],[
			'name' => '大会员签到',
			'id' => 'dhyqd',
			'vip' => 1,
			'gnid'=> 2
		],[
			'name' => '微视签到',
			'id' => 'wsqd',
			'vip' => 1,
			'gnid'=> 2
		],[
			'name' => 'QQ运动',
			'id' => 'yundong',
			'vip' => 1,
			'gnid'=> 2
		],[
			'name' => '空间人气',
			'id' => 'renqi',
			'vip' => 1,
			'gnid'=> 1
		],[
			'name' => '网易云签到',
			'id' => 'wyqd',
			'vip' => 1,
			'gnid'=> 3
		]
	];
	return $data;
}

function cylb_name($type)
{
    switch ($type) {
        case 'zan':
            $Name = '说说秒赞';
            $id = 1;
            break;
		case 'hzmp':
            $Name = '互赞名片赞';
            $id = 2;
            break;
        case 'reply':
            $Name = '说说秒评';
            $id = 3;
            break;
        case 'mqq':
            $Name = '手Q加速';
            $id = 4;
            break;
        case 'sy':
            $Name = '手游加速';
            $id = 5;
            break;
		case 'shuo':
            $Name = '自动说说';
            $id = 6;
            break;
        case 'zf':
            $Name = '转发说说';
            $id = 7;
            break;
        case 'qipao':
            $Name = '百变气泡';
            $id = 8;
            break;
        case 'ql':
            $Name = '情侣积分';
            $id = 9;
            break;
        case 'del':
            $Name = '删除说说';
            $id = 10;
            break;
        case 'delly':
            $Name = '删除留言';
            $id = 11;
            break;
		case 'ht':
            $Name = '花藤代养';
            $id = 12;
            break;
		 case 'qd':
            $Name = '空间签到';
            $id = 13;
            break;
		case 'blqd':
            $Name = '部落签到';
            $id = 14;
            break;
        case 'qbqd':
            $Name = '钱包签到';
            $id = 15;
            break;
        case 'hyqd':
            $Name = '会员签到';
            $id = 16;
            break;
        case 'lzqd':
            $Name = '蓝钻签到';
            $id = 17;
            break;
        case 'hzqd':
            $Name = '黄钻签到';
            $id = 18;
            break;
        case 'fzqd':
            $Name = '粉钻签到';
            $id = 19;
            break;
        case 'hlwqd':
            $Name = '好莱坞签到';
            $id = 20;
            break;
		case 'dhyqd':
            $Name = '大会员签到';
            $id = 21;
            break;
		case 'wsqd':
            $Name = '微视签到';
            $id = 22;
            break;
		case 'renqi':
            $Name = '空间人气';
            $id = 23;
            break;
		case 'wyqd':
            $Name = '网易云签到';
            $id = 24;
            break;
		case 'yundong':
            $Name = 'QQ运动';
            $id = 25;
            break;
		case 'qunqd':
            $Name = '群聊签到';
            $id = 26;
            break;
    }
    $data = [
        'id' => $id,
        'name' => $Name,
    ];
    return $data;
}

function get_info($cookies, $return = NULL)
{
    preg_match('/skey=@(.{9});/', $cookies, $skey);
    preg_match('/superkey=(.*?);/', $cookies, $superkey);
    preg_match('/sid=(.*?);/', $cookies, $sid);
    preg_match('/p_skey=(.{44});/', $cookies, $p_skey);
    $skey = "@" . $skey[1];
    $pskey = $p_skey[1];
    $sid = $sid[1];
    $superkey = $superkey[1];
    $arr = array('skey' => $skey, 'pskey' => $pskey, 'sid' => $sid, 'superkey' => $superkey);
    if ($return) {
        return $arr["{$return}"];
    } else {
        return $arr;
    }
}

function send_post($url, $post_data)
{

    $postdata = http_build_query($post_data);
    $options = array(
        'http' => array(
            'method' => 'POST',//注意要大写
            'header' => 'Content-type:application/x-www-form-urlencoded',
            'content' => $postdata
        )
    );
    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    return $result;
}

function send_mail($to, $sub, $msg)
{
    if (config('sys_is_mail_api') == 0) {//使用官方发信，无需配置
        $mail_api = 'http://api.emapi.cn/api/mzemail/send.php';
        $post['to'] = $to;
        $post['title'] = $sub;
        $post['html'] = $msg;
        $post['nick'] = config('web_webname');
        $data = send_post($mail_api, $post);
        $res = json_decode($data, true);
        if ($res['code'] == 0) {
            return true;
        } else {
            return false;
        }
    } elseif (config('sys_is_mail_api') == 1) {//使用本地接口发信，需配置邮箱信息
        $From = config('sys_mail_name');
        $Host = config('sys_mail_smtp');
        $Port = config('sys_mail_port');
        $SMTPAuth = 1;
        $Username = config('sys_mail_name');
        $Password = config('sys_mail_pwd');
        $Nickname = config('web_webname');
        $SSL = config('sys_mail_port') == 465 ? 1 : 0;
        $mail = new SMTP($Host, $Port, $SMTPAuth, $Username, $Password, $SSL);
        $mail->att = array();
        if ($mail->send($to, $From, $sub, $msg, $Nickname)) {
            return true;
        } else {
            return false;
        }
    }
}

function strexists($string, $find)
{
    return !(strpos($string, $find) === FALSE);
}

function dstrpos($string, $arr)
{
    if (empty($string)) {
        return false;
    }
    foreach ((array)$arr as $v) {
        if (strpos($string, $v) !== false) {
            return true;
        }
    }
    return false;
}

function check_mobile()   
{   
  $_SERVER['ALL_HTTP'] = isset($_SERVER['ALL_HTTP']) ? $_SERVER['ALL_HTTP'] : '';   
  $mobile_browser = '0';   
  if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|iphone|ipad|ipod|android|xoom)/i', strtolower($_SERVER['HTTP_USER_AGENT'])))   
	$mobile_browser++;   
  if((isset($_SERVER['HTTP_ACCEPT'])) and (strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml') !== false))   
	$mobile_browser++;   
  if(isset($_SERVER['HTTP_X_WAP_PROFILE']))   
	$mobile_browser++;   
  if(isset($_SERVER['HTTP_PROFILE']))   
	$mobile_browser++;   
  $mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4));   
  $mobile_agents = array(   
		'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',   
		'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',   
		'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',   
		'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',   
		'newt','noki','oper','palm','pana','pant','phil','play','port','prox',   
		'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',   
		'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',   
		'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',   
		'wapr','webc','winw','winw','xda','xda-'  
		);   
  if(in_array($mobile_ua, $mobile_agents))   
	$mobile_browser++;   
  if(strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== false)   
	$mobile_browser++;   
  // Pre-final check to reset everything if the user is on Windows   
  if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows') !== false)   
	$mobile_browser=0;   
  // But WP7 is also Windows, with a slightly different characteristic   
  if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows phone') !== false)   
	$mobile_browser++;   
  if($mobile_browser>0)   
	return true;   
  else 
	return false;   
}

function authcode($string, $operation = '', $key = '', $expiry = 0)
{
    $ckey_length = 4;
    $key = md5($key ? $key : 'zyzs');
    $keya = md5(substr($key, 0, 16));
    $keyb = md5(substr($key, 16, 16));
    $keyc = $ckey_length ? $operation == 'DECODE' ? substr($string, 0, $ckey_length) : substr(md5(microtime()), -$ckey_length) : '';
    $cryptkey = $keya . md5($keya . $keyc);
    $key_length = strlen($cryptkey);
    $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0) . substr(md5($string . $keyb), 0, 16) . $string;
    $string_length = strlen($string);
    $result = '';
    $box = range(0, 255);
    $rndkey = array();
    for ($i = 0; $i <= 255; $i++) {
        $rndkey[$i] = ord($cryptkey[$i % $key_length]);
    }
    for ($j = $i = 0; $i < 256; $i++) {
        $j = ($j + $box[$i] + $rndkey[$i]) % 256;
        $tmp = $box[$i];
        $box[$i] = $box[$j];
        $box[$j] = $tmp;
    }
    for ($a = $j = $i = 0; $i < $string_length; $i++) {
        $a = ($a + 1) % 256;
        $j = ($j + $box[$a]) % 256;
        $tmp = $box[$a];
        $box[$a] = $box[$j];
        $box[$j] = $tmp;
        $result .= chr(ord($string[$i]) ^ $box[($box[$a] + $box[$j]) % 256]);
    }
    if ($operation == 'DECODE') {
        if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26) . $keyb), 0, 16)) {
            return substr($result, 26);
        } else {
            return '';
        }
    } else {
        return $keyc . str_replace('=', '', base64_encode($result));
    }
}

function get_mail_tempale($type, $data, $sign)
{
    if ($type == 1) {//验证码类型
        return "<div id=\"cTMail-Wrap\" style=\"box-sizing:border-box;text-align:center;min-width:320px; max-width:660px; border:1px solid #f6f6f6; background-color:#f7f8fa; margin:auto; padding:20px 0 30px; font-family:&#39;helvetica neue&#39;,PingFangSC-Light,arial,&#39;hiragino sans gb&#39;,&#39;microsoft yahei ui&#39;,&#39;microsoft yahei&#39;,simsun,sans-serif\">
    <div class=\"main-content\" style=\"\">
        <table style=\"width:100%;font-weight:300;margin-bottom:10px;border-collapse:collapse\">
            <tbody>
            <tr style=\"font-weight:300\">
                <td style=\"width:3%;max-width:30px;\"></td>
                <td style=\"max-width:600px;\">
                    <p style=\"height:2px;background-color: #00a4ff;border: 0;font-size:0;padding:0;width:100%;margin-top:20px;\"></p>
                    <div id=\"cTMail-inner\" style=\"background-color:#fff; padding:23px 0 20px;box-shadow: 0px 1px 1px 0px rgba(122, 55, 55, 0.2);text-align:left;\">
                        <table style=\"width:100%;font-weight:300;margin-bottom:10px;border-collapse:collapse;text-align:left;\">
                            <tbody>
                            <tr style=\"font-weight:300\">
                                <td style=\"width:3.2%;max-width:30px;\"></td>
                                <td style=\"max-width:480px;text-align:left;\">
                                    <h1 id=\"cTMail-title\" style=\"font-weight:bold;font-size:20px; line-height:36px; margin:0 0 16px;\">" . config('web_webname') . "-" . $data . "</h1>
                                    <p class=\"cTMail-content\" style=\"font-size: 14px; color: rgb(51, 51, 51); line-height: 24px; margin: 6px 0px 0px; word-wrap: break-word; word-break: break-all;\">欢迎您使用" . config('web_webname') . "（" . get_domain() . "）。</p>
                                    <p class=\"cTMail-content\" style=\"font-size: 14px; color: rgb(51, 51, 51); line-height: 24px; margin: 6px 0px 0px; word-wrap: break-word; word-break: break-all;\">您的验证码是：" . $sign . "      有效时间5分钟，请尽快完成后续操作</p>
                                    <p class=\"cTMail-content\" style=\"font-size: 14px; color: rgb(51, 51, 51); line-height: 24px; margin: 6px 0px 0px; word-wrap: break-word; word-break: break-all;\">注册请求时间：" . date("Y-m-d H:i:s") . "</p>
                                    <p class=\"cTMail-content\" style=\"font-size: 14px; color: rgb(51, 51, 51); line-height: 24px; margin: 6px 0px 0px; word-wrap: break-word; word-break: break-all;\">注册请求地点：" . get_ip_city(real_ip()) . "（" . real_ip() . "）</p>
                                    <p class=\"cTMail-content\" style=\"line-height: 24px; margin: 6px 0px 0px; overflow-wrap: break-word; word-break: break-all;\"><span style=\"color: rgb(51, 51, 51); font-size: 14px;\">如果非本人操作，请忽略该邮件！</span><br/>
                                    </p>
                                    <dl style=\"font-size: 14px; color: rgb(51, 51, 51); line-height: 18px;\">
                                        <dd style=\"margin: 0px 0px 6px; padding: 0px; font-size: 12px; line-height: 22px;\"><p id=\"cTMail-sender\" style=\"font-size: 14px; line-height: 26px; word-wrap: break-word; word-break: break-all; margin-top: 32px;\">此致 <br  />
                                            <strong>" . config('web_webname') . "</strong></p>
                                        </dd>
                                    </dl>
                                </td>
                                <td style=\"width:3.2%;max-width:30px;\"></td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
</div>";
    } elseif ($type == '3') {
        return "<div id=\"cTMail-Wrap\" style=\"box-sizing:border-box;text-align:center;min-width:320px; max-width:660px; border:1px solid #f6f6f6; background-color:#f7f8fa; margin:auto; padding:20px 0 30px; font-family:&#39;helvetica neue&#39;,PingFangSC-Light,arial,&#39;hiragino sans gb&#39;,&#39;microsoft yahei ui&#39;,&#39;microsoft yahei&#39;,simsun,sans-serif\">
    <div class=\"main-content\" style=\"\">
        <table style=\"width:100%;font-weight:300;margin-bottom:10px;border-collapse:collapse\">
            <tbody>
            <tr style=\"font-weight:300\">
                <td style=\"width:3%;max-width:30px;\"></td>
                <td style=\"max-width:600px;\">
                    <p style=\"height:2px;background-color: #00a4ff;border: 0;font-size:0;padding:0;width:100%;margin-top:20px;\"></p>
                    <div id=\"cTMail-inner\" style=\"background-color:#fff; padding:23px 0 20px;box-shadow: 0px 1px 1px 0px rgba(122, 55, 55, 0.2);text-align:left;\">
                        <table style=\"width:100%;font-weight:300;margin-bottom:10px;border-collapse:collapse;text-align:left;\">
                            <tbody>
                            <tr style=\"font-weight:300\">
                                <td style=\"width:3.2%;max-width:30px;\"></td>
                                <td style=\"max-width:480px;text-align:left;\">
                                    <h1 id=\"cTMail-title\" style=\"font-weight:bold;font-size:20px; line-height:36px; margin:0 0 16px;\">" . config('web_webname') . "-邮件提醒</h1>
                                    <p id=\"cTMail-userName\" style=\"font-size:14px;color:#333; line-height:24px; margin:0;\">尊敬的：" . $data['nickname'] . "，您好！</p>
                                    <p class=\"cTMail-content\" style=\"font-size: 14px; color: rgb(51, 51, 51); line-height: 24px; margin: 6px 0px 0px; word-wrap: break-word; word-break: break-all;\">这封信是由" . config('web_webname') . "（" . get_domain() . "）发送的。</p>
                                    <p class=\"cTMail-content\" style=\"font-size: 14px; color: rgb(51, 51, 51); line-height: 24px; margin: 6px 0px 0px; word-wrap: break-word; word-break: break-all;\">您成功在我们网站添加了一个QQ</p>
                                    <p class=\"cTMail-content\" style=\"font-size: 14px; color: rgb(51, 51, 51); line-height: 24px; margin: 6px 0px 0px; word-wrap: break-word; word-break: break-all;\">添加时间：" . date('Y-m-d H:i:s') . ",</p>
                                    <p class=\"cTMail-content\" style=\"font-size: 14px; color: rgb(51, 51, 51); line-height: 24px; margin: 6px 0px 0px; word-wrap: break-word; word-break: break-all;\">提交者信息：" . get_ip_city(real_ip()) . "（" . real_ip() . "）</p>
                                   <br/>
                                    </p>
                                    <dl style=\"font-size: 14px; color: rgb(51, 51, 51); line-height: 18px;\">
                                        <dd style=\"margin: 0px 0px 6px; padding: 0px; font-size: 12px; line-height: 22px;\"><p id=\"cTMail-sender\" style=\"font-size: 14px; line-height: 26px; word-wrap: break-word; word-break: break-all; margin-top: 32px;\">此致 <br  />
                                            <strong>" . config('web_webname') . "</strong></p>
                                        </dd>
                                    </dl>
                                </td>
                                <td style=\"width:3.2%;max-width:30px;\"></td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
</div>";
    } elseif ($type == '4') {
        return "<div id=\"cTMail-Wrap\" style=\"box-sizing:border-box;text-align:center;min-width:320px; max-width:660px; border:1px solid #f6f6f6; background-color:#f7f8fa; margin:auto; padding:20px 0 30px; font-family:&#39;helvetica neue&#39;,PingFangSC-Light,arial,&#39;hiragino sans gb&#39;,&#39;microsoft yahei ui&#39;,&#39;microsoft yahei&#39;,simsun,sans-serif\">
    <div class=\"main-content\" style=\"\">
        <table style=\"width:100%;font-weight:300;margin-bottom:10px;border-collapse:collapse\">
            <tbody>
            <tr style=\"font-weight:300\">
                <td style=\"width:3%;max-width:30px;\"></td>
                <td style=\"max-width:600px;\">
                    <p style=\"height:2px;background-color: #00a4ff;border: 0;font-size:0;padding:0;width:100%;margin-top:20px;\"></p>
                    <div id=\"cTMail-inner\" style=\"background-color:#fff; padding:23px 0 20px;box-shadow: 0px 1px 1px 0px rgba(122, 55, 55, 0.2);text-align:left;\">
                        <table style=\"width:100%;font-weight:300;margin-bottom:10px;border-collapse:collapse;text-align:left;\">
                            <tbody>
                            <tr style=\"font-weight:300\">
                                <td style=\"width:3.2%;max-width:30px;\"></td>
                                <td style=\"max-width:480px;text-align:left;\">
                                    <h1 id=\"cTMail-title\" style=\"font-weight:bold;font-size:20px; line-height:36px; margin:0 0 16px;\">" . config('web_webname') . "-邮件提醒</h1>
                                    <p id=\"cTMail-userName\" style=\"font-size:14px;color:#333; line-height:24px; margin:0;\">尊敬的：" . $data . "，您好！</p>
                                    <p class=\"cTMail-content\" style=\"font-size: 14px; color: rgb(51, 51, 51); line-height: 24px; margin: 6px 0px 0px; word-wrap: break-word; word-break: break-all;\">这封信是由" . config('web_webname') . "（" . get_domain() . "）发送的。</p>
                                    <p class=\"cTMail-content\" style=\"font-size: 14px; color: rgb(51, 51, 51); line-height: 24px; margin: 6px 0px 0px; word-wrap: break-word; word-break: break-all;\">您在我们网站挂机的QQ：" . $data . " 挂机状态已失效，请及时更新</p>
                                    <p class=\"cTMail-content\" style=\"font-size: 14px; color: rgb(51, 51, 51); line-height: 24px; margin: 6px 0px 0px; word-wrap: break-word; word-break: break-all;\">失效时间：" . date('Y-m-d H:i:s') . ",</p>
                                    <p class=\"cTMail-content\" style=\"font-size: 14px; color: rgb(51, 51, 51); line-height: 24px; margin: 6px 0px 0px; word-wrap: break-word; word-break: break-all;\"><a href='" . get_domain() . "'>点我前往</a></p>
                                   <br/>
                                    </p>
                                    <dl style=\"font-size: 14px; color: rgb(51, 51, 51); line-height: 18px;\">
                                        <dd style=\"margin: 0px 0px 6px; padding: 0px; font-size: 12px; line-height: 22px;\"><p id=\"cTMail-sender\" style=\"font-size: 14px; line-height: 26px; word-wrap: break-word; word-break: break-all; margin-top: 32px;\">此致 <br  />
                                            <strong>" . config('web_webname') . "</strong></p>
                                        </dd>
                                    </dl>
                                </td>
                                <td style=\"width:3.2%;max-width:30px;\"></td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
</div>";
    }
}


function ws($id=1)
{
	if($id == 1 || $id=''){
		if(config('sys_chat_https')==1){
			$wss = 'wss://'.$_SERVER['HTTP_HOST'].'/wss';
		}else{
			$wss = 'ws://wss.phpfn.cn:9501';
		}
	}else{
		if(config('sys_chat_https')==1){
			$wss = 'wss://'.$_SERVER['HTTP_HOST'].'/wss';
		}else{
			$wss = 'ws://wss.phpfn.cn:9501';
		}
	}
	return $wss;
}